package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.vo.PageResult;
import com.flyduck.common.vo.Result;
import com.flyduck.system.mapper.SysUserMapper;
import com.flyduck.system.service.SysUserService;
import com.flyduck.system.vo.user.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: flyduck-platform
 * @description: 系统:用户接口
 * @author: flyduck
 * @create: 2021-02-05 21:05
 **/
@Api(tags = "系统:用户接口")
@RestController
@RequestMapping("/system/sysUserController")
public class SysUserController {


    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation("查询用户分页")
    @PostMapping("/page")
    public Result getUserPageList(@RequestBody SysUserReqVO reqVo,
                              @RequestParam(value = "page",required = true) Integer page,
                              @RequestParam(value = "size",required = true) Integer size){
        PageResult<SysUserRespVO> userPage = sysUserService.getUserPageList(reqVo, page, size);
        return Result.success(userPage);
    }


    @IgnoreAuth
    @ApiOperation("查询用户详情")
    @GetMapping("/detail")
    public Result getUserDetail(@RequestParam(value = "id",required = true) Long id){
        SysUserDetailRespVO respVO = sysUserService.getUserDetail(id);
        return Result.success(respVO);
    }

    @ApiOperation("新增用户")
    @PostMapping("/addUser")
    public Result add(@RequestBody @Validated SysUserAddReqVO reqVo){
        boolean flag = sysUserService.addUser(reqVo);
        return Result.success(flag,"新增成功");
    }

    @ApiOperation("编辑用户")
    @PutMapping("/updateUser")
    public Result update(@RequestBody @Validated SysUserUpdateReqVO reqVo){
        boolean flag = sysUserService.updateUser(reqVo);
        return Result.success(flag,"修改成功");
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/delete")
    public Result deleteUser(@RequestParam(value = "id",required = true) Long id){
        boolean flag = sysUserService.deleteUser(id);
        return Result.success(flag,"删除成功");
    }




}
